<%@ page language="java" pageEncoding="UTF-8" import="com.chinapost.util.AuthUtil"%>
<%@ taglib prefix="my" uri="/WEB-INF/tlds/permission.tld" %>
<%
	AuthUtil authUtil = new AuthUtil(session);
%>
<script type="text/javascript">
	var fczy_datagrid;
	$(function() {
		fczy_datagrid = $('#fczy_manager_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/fczyAction!datagrid.action',
			pagination : true,
			pageSize : 20,
			pageList : [  10, 20, 30, 40, 50 ],
			border : false,
			fit : true,
			fitColumns : true,
			idField : 'cid',
			sortName : 'cmodifydate',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : true,
			columns : [ [ {
				title : 'id',
				field : 'cid',
				align : "center",
				width : 100,
				checkbox : true
			}, {
				title : '所属机构',
				field : 'deptName',
				align : "center",
				width : 160
			}, {
				title : '网点名称',
				field : 'wdname',
				align : "center",
				width : 160
			}, {
				title : '房产占用费（月租金）',
				field : 'czczyf',
				align : "center",
				width : 160
			},{
				title : '创建日期',
				field : 'ccreatedate',
				align : "center",
				width : 100
			},
			{
				title : '修改日期',
				field : 'cmodifydate',
				align : "center",
				width : 100
			},
			{
				field : 'action',
				title : '操作',
				width : 100,
				align : 'center',
				formatter : function(value, row, index) {
					var str='';
                	<%if (authUtil.isAuth("/fczyAction!fczyEdit.action")){%>
                	str += sy.fs('<img onclick="fczyEdit(\'{0}\');" src="{1}" style="cursor: pointer;" title="修改"/>&nbsp;',row.cid,'${pageContext.request.contextPath}/css/themes/icons/pencil.png');
                	<%}%>
                	<%if (authUtil.isAuth("/fczyAction!delete.action")){%>
                	str += sy.fs('<img onclick="fczyDelete(\'{0}\');" src="{1}" style="cursor: pointer;" title="删除"/>&nbsp;',row.cid,'${pageContext.request.contextPath}/css/themes/icons/no.png');
                	<%}%>
                	return str;
				}
			} ] ],
			toolbar : '#fczy_toolbar'
		});
		$('#fczy_manager_dept').combotree({
			lines:true,
			url:'deptAction!do_combotree.action',
			panelHeight:260,
			required:true,
			editable:false,
			idField:'id',
			textField:'text',
			parentField:'pid',
			onBeforeSelect: function(node) {
		            if (!$(this).tree('isLeaf', node.target)) {
		                return false;
		            }
		        },
		        onClick: function(node) {
		            if (!$(this).tree('isLeaf', node.target)) {
		                $('#fczy_manager_dept').combo('showPanel');
		            }
		        },
		        onSelect:function(node){
					$('#fczy_manager_wd').combobox('clear');
					$('#fczy_manager_wd').combobox('reload','wdxxAction!do_combobox.action?deptId='+node.id);
				}
		});
		 $('#fczy_manager_wd').combobox({
			 url:'wdxxAction!do_combobox.action?deptId=${sessionInfo.deptid}',
			 valueField:'cid',
			 textField:'cname'
		 });
		$('#fczy_manager_dept').combotree('setValue','${sessionInfo.deptid}');
	});
	
	function fczyEdit(cid) {
		if (cid != undefined) {
			$('#fczy_manager_datagrid').datagrid('unselectAll');
			$('#fczy_manager_datagrid').datagrid('selectRecord', cid);
		}
		var rows = $('#fczy_manager_datagrid').datagrid('getSelected');
		var p = parent.sy.dialog({
			title : '网点房产占用费修改',
			iconCls : 'icon-edit',
			href : '${pageContext.request.contextPath}/fczyAction!fczyEdit.action',
			width : 400,
			height : 200,
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/fczyAction!edit.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								fczy_datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ],
			onLoad : function() {
				var f = p.find('form');
				 $('#fczy_edit_dept').combotree({
						lines:true,
						url:'deptAction!do_combotree.action',
						panelHeight:260,
						required:true,
						editable:false,
						idField:'id',
						textField:'text',
						parentField:'pid',
						 onBeforeSelect: function(node) {
					            if (!$(this).tree('isLeaf', node.target)) {
					                return false;
					            }
					        },
					        onClick: function(node) {
					            if (!$(this).tree('isLeaf', node.target)) {
					                $('#fczy_edit_dept').combo('showPanel');
					            }
					        },
						onSelect:function(node){
							$('#fczy_edit_wd').combobox('setValue','');
							$('#fczy_edit_wd').combobox('reload','wdxxAction!do_combobox.action?deptId='+node.id);
						}
					}); 
				 $('#fczy_edit_wd').combobox({
					 url:'wdxxAction!do_combobox.action?deptId='+rows.deptId,
					 required:true,
					 valueField:'cid',
					 textField:'cname'
				 });
				f.form('load', rows);
				
			}
		});
	};
	function fczyAppend() {
		var p = parent.sy.dialog({
			title : '添加网点房产占用费记录',
			iconCls : 'icon-append',
			href : '${pageContext.request.contextPath}/fczyAction!fczyAdd.action',
			width : 400,
			height : 200,
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/fczyAction!add.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								fczy_datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ]
		});
	}
	function fczyRemove() {
		var rows = fczy_datagrid.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			parent.sy.messagerConfirm('请确认', '是否删除当前所选记录？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].cid);
					}
					$.ajax({
						url : '${pageContext.request.contextPath}/fczyAction!delete.action',
						data : {
							ids : ids.join(',')
						},
						dataType : 'json',
						success : function(d) {
							fczy_datagrid.datagrid('load');
							$('#fczy_manager_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
							parent.sy.messagerShow({
								title : '提示',
								msg : d.msg
							});
						}
					});
				}
			});
		} else {
			parent.sy.messagerAlert('提示', '请选择要删除的记录！', 'error');
		}
	};

	function fczyDelete(cid) {
		$('#fczy_manager_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
		$('#fczy_manager_datagrid').datagrid('checkRow', $('#fczy_manager_datagrid').datagrid('getRowIndex', cid));
		fczyRemove();
	}


	function fczyImport() {
		var p = parent.sy.dialog({
			title : '导入网点房产占用费数据',
			iconCls : 'icon-import',
			href : '${pageContext.request.contextPath}/fczyAction!fczyImport.action',
			width : 510,
			height : 210,
			buttons : [ {
				text : '导入',
				iconCls : 'icon-accept',
				handler : function() {
					$.ajaxFileUpload({
						url : 'uploadFileAction!upload.action',//用于文件上传的服务器端请求地址  
						secureuri : false,//一般设置为false  
						fileElementId : 'fczy_import_file',//文件上传空间的id属性  <input type="file" id="file" name="file" />  
						dataType : 'text',//返回值类型 json，text  
						success : function(d, status) //服务器成功响应处理函数  
						{
							var json = $.parseJSON(d);
							if (json.state) {
								$.messager.progress({
									text : '正在处理，请稍候...',
									interval : 100
								});
								$.post("fczyAction!addFczys.action", {
									filename : json.filename,
									createUserId : '${sessionInfo.userId}',
									deptId : $('#fczy_import_dept').combotree('getValue')
								}, function(rsp) {
									if (rsp.success) {
										fczy_datagrid.datagrid('reload');
										p.dialog('close');
									}
									$.messager.progress('close');
									parent.sy.messagerAlert('提示', rsp.msg, 'info');
								}, "JSON");
							} else {
								$.messager.progress('close');
								parent.sy.messagerShow({
									msg : json.msg,
									title : '提示'
								});
							}
						},
						error : function(data, status, e)//服务器响应失败处理函数  
						{
							parent.sy.messagerAlert('错误', e, 'error');
						}
					});
				}
			} ]
		});
	};


	function _searchFczy() {
		fczy_datagrid.datagrid('load', sy.serializeObject($('#fczy_search_form')));
		fczy_datagrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
	};
	function _cleanSearchFczy() {
		$('#fczy_manager_wd').combobox('setValue','');
		$('#fczy_manager_dept').combotree('setValue','${sessionInfo.deptid}');
		fczy_datagrid.datagrid('load', sy.serializeObject($('#fczy_search_form')));
		fczy_datagrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
	};
</script>




<div class="easyui-layout" data-options="fit:true" style="overflow: hidden;">
	<div data-options="region:'north',title:'查询记录',iconCls:'icon-search'" style="height: 80px;padding:5px;overflow: hidden;">
		<div style="padding:5px">
			<form method="post" id="fczy_search_form" style="display:inline">
			<span>所属机构：</span>
			<input type="text" id="fczy_manager_dept"  name="deptId" style="width:200px"/>&nbsp;&nbsp;
			<span >所属网点：
				<input type="text" id="fczy_manager_wd"  name="wdid"  style="width:200px"/>&nbsp;&nbsp;	
			</span>
			</form>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="_searchFczy();">查询</a>&nbsp; <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onClick="_cleanSearchFczy();">清空</a>
		</div>
	</div>
	<div data-options="region:'center',title:'数据列表',border:true,iconCls:'icon-menu'" style="overflow: hidden;">
		<table id="fczy_manager_datagrid"></table>
	</div>
</div>
<div id="fczy_toolbar" style="display: none;" >
<table  class="toolbar" >
	<tr>
		<my:per url="/fczyAction!fczyAdd.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-append',plain:true" onclick="fczyAppend();">新增</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
		<my:per url="/fczyAction!delete.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-delete',plain:true" onclick="fczyRemove()">批量删除</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
		<my:per url="/fczyAction!fczyImport.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-import',plain:true" onclick="fczyImport()">批量导入</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
	</tr>
</table>
</div>
